package cn.stylefeng.guns.modular.hx.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.order.entity.HxOrderPutDetailed;
import cn.stylefeng.guns.modular.hx.order.mapper.HxOrderPutDetailedMapper;
import cn.stylefeng.guns.modular.hx.order.model.params.HxOrderPutDetailedParam;
import cn.stylefeng.guns.modular.hx.order.model.result.HxOrderPutDetailedResult;
import  cn.stylefeng.guns.modular.hx.order.service.HxOrderPutDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 入库订单明细表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-08-05
 */
@Service
public class HxOrderPutDetailedServiceImpl extends ServiceImpl<HxOrderPutDetailedMapper, HxOrderPutDetailed> implements HxOrderPutDetailedService {

    @Override
    public void add(HxOrderPutDetailedParam param){
        HxOrderPutDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxOrderPutDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxOrderPutDetailedParam param){
        HxOrderPutDetailed oldEntity = getOldEntity(param);
        HxOrderPutDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxOrderPutDetailedResult findBySpec(HxOrderPutDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<HxOrderPutDetailedResult> findListBySpec(HxOrderPutDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxOrderPutDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxOrderPutDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxOrderPutDetailed getOldEntity(HxOrderPutDetailedParam param) {
        return this.getById(getKey(param));
    }

    private HxOrderPutDetailed getEntity(HxOrderPutDetailedParam param) {
        HxOrderPutDetailed entity = new HxOrderPutDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<HxOrderPutDetailedResult> findListBySpec2(HxOrderPutDetailedParam param) {
		return this.baseMapper.findListBySpec2(param);
	}

	@Override
	public boolean saveBatchList(List<HxOrderPutDetailedParam> detailedList) {
		return this.baseMapper.saveBatchList(detailedList);
	}

	@Override
	public List<HxOrderPutDetailedResult> totalListByGandPSpec(HxOrderPutDetailedParam hxOrderPutDetailedParam) {
		return this.baseMapper.totalListByGandPSpec(hxOrderPutDetailedParam);
	}

	@Override
	public void deleteBySpec(HxOrderPutDetailedParam detailedParam) {
		this.baseMapper.deleteBySpec(detailedParam);
	}

}
